package lium.lbs.lbsim.activity

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.buz.hjcdriver.bean.AResultBean
import com.lmlibrary.Constants
import com.lmlibrary.bean.ResponseBean
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_group_name.*
import lium.lbs.lbsim.R
import lium.lbs.lbsim.jgchat.application.GJApp
import lium.lbs.lbsim.utils.SpUtils
import lium.lbs.lbsim.utils.ToastUtils
import lium.lbs.lbsim.utils.callbck.DialogCallback
import java.util.HashMap

class GroupNameActivity : BaseActivity() {

    var groupId: String? = null

    override fun getLayoutId(): Int {
        return R.layout.activity_group_name
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("修改群名")
        addOnClickListeners(
            R.id.to_name
        )
        groupId = intent.getStringExtra(GJApp.MY_GROUP_ID)
    }


    override fun onClick(v: View?) {
        super.onClick(v)
        when (v!!.id) {
            R.id.to_name -> {
                getDataNotice()
            }
        }
    }

    fun getDataNotice() {
        if (TextUtils.isEmpty(name_content.text.toString())){
            return
        }
        val param = HashMap<String, String>()
        param["memberId"] = SpUtils.getInstance().get(Constants.memberId, "") as String
        param["groupId"] = groupId.toString()
        param["name"] = name_content.text.toString()
        postData(
            "/group/updateGroupInfo",
            param,
            object : DialogCallback<ResponseBean<AResultBean>>(this) {
                override fun onSuccess(response: Response<ResponseBean<AResultBean>>) {
                    setDataList(response.body().status)
                }
            })
    }

    fun setDataList(msg: Int) {
        ToastUtils.showLongToast("修改成功")
        setResult(203)
        finish()
    }



    override fun getNetWorkData() {

    }
}
